package megrez.oss.minio.web.vo;

import java.time.ZonedDateTime;
import java.util.Map;

import io.minio.messages.Item;
import lombok.Data;

/**
 * <code>io.minio.messages.Item</code> 包装实体类
 *  
 * @author Lucky Yang
 * @since 2.6.9
 */
@Data
public class ItemVO {
    private String etag;
    private String objectName;
    private ZonedDateTime lastModified;
    private String owner;
    private long size;
    private String storageClass;
    private boolean isLatest;
    private String versionId;
    private boolean isDir;
    private boolean isDeleteMarker;
    private String encodingType;
    private Map<String, String> userMetadata;   

    public static ItemVO of(Item item) {
        ItemVO rslt = new ItemVO();
        // .encodingType(item.en)
        rslt.setEtag(item.etag());
        rslt.setDeleteMarker(item.isDeleteMarker());
        rslt.setDir(item.isDir());
        rslt.setLatest(item.isLatest());
        // .lastModified(null)
        rslt.setObjectName(item.objectName());
        rslt.setOwner(item.owner() != null ? item.owner().id() + "-" + item.owner().displayName() : null);
        rslt.setSize(item.size());
        rslt.setStorageClass(item.storageClass());
        rslt.setUserMetadata(item.userMetadata());
        rslt.setVersionId(item.versionId());
        return rslt;
    }
}
